package leetcode.f1t100;

import leetcode.struct.ListNode;

/**
 * 删除有序链表中的重复值
 * Q83_RemoveDuplicatesFromSortedList
 *
 * @author lichx
 * @createTime 2024/1/29 16:08
 */
public class Q83_RemoveDuplicatesFromSortedList {

    public static void main(String[] args) {
        Q83_RemoveDuplicatesFromSortedList bean = new Q83_RemoveDuplicatesFromSortedList();
        ListNode listNode = new ListNode(1, new ListNode(1, new ListNode(2)));

        bean.deleteDuplicates(listNode);
        while (listNode != null) {
            System.out.println(listNode.val);
            listNode = listNode.next;
        }

    }

    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;
        while (cur != null) {
            if(cur.next != null && cur.next.val == cur.val){
                cur.next = cur.next.next;
            }else{
                cur = cur.next;
            }
        }
        return head;
    }

}
